package com.rockgle.reader;

import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.ListView;

import com.rockgle.widget.PostListAdapter;

public class FeedViewOnScrollListener implements OnScrollListener{

	private PostListAdapter adapter;
	private DBContentLoader cl=null;
	
	public FeedViewOnScrollListener(PostListAdapter adapter){
		this.adapter = adapter;
		cl = new DBContentLoader();
	}
	
	@Override
	public void onScroll(AbsListView view, int firstVisibleItem,
			int visibleItemCount, int totalItemCount) {
			if(visibleItemCount>0){
				if(!cl.isAllDownloaded()){
					ListView lw = (ListView)view;
					int numvisibles = firstVisibleItem+visibleItemCount;
					int longadapter = lw.getAdapter().getCount();
					if (numvisibles>0 && numvisibles == longadapter){
						//cl = new DBContentLoader();
						cl.execute(adapter);
					}
				}
			}
	}

	@Override
	public void onScrollStateChanged(AbsListView view, int scrollState) {}

}
